<!DOCTYPE html>
<html lang="en-US">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>C和C++运算符规则记忆 | whoway</title>
    <meta name="description" content="Personal Blog Website">
    <link rel="icon" href="/images/photo.jpg">
  <link rel="manifest" href="/images/photo.jpg">
  <link rel="apple-touch-icon" href="/images/photo.jpg">
  <meta http-quiv="pragma" cotent="no-cache">
  <meta http-quiv="pragma" cotent="no-cache,must-revalidate">
  <meta http-quiv="expires" cotent="0">
    
    <link rel="preload" href="/assets/css/0.styles.0dbae9ec.css" as="style"><link rel="preload" href="/assets/js/app.c70e21ad.js" as="script"><link rel="preload" href="/assets/js/22.f78666de.js" as="script"><link rel="prefetch" href="/assets/js/10.15222a53.js"><link rel="prefetch" href="/assets/js/100.7e0e5a86.js"><link rel="prefetch" href="/assets/js/101.efd59f25.js"><link rel="prefetch" href="/assets/js/102.dfbdc06c.js"><link rel="prefetch" href="/assets/js/103.d3ab2109.js"><link rel="prefetch" href="/assets/js/104.117957ef.js"><link rel="prefetch" href="/assets/js/105.046e8ff3.js"><link rel="prefetch" href="/assets/js/106.aebdc17d.js"><link rel="prefetch" href="/assets/js/107.248733c2.js"><link rel="prefetch" href="/assets/js/108.a2fecadc.js"><link rel="prefetch" href="/assets/js/109.35196857.js"><link rel="prefetch" href="/assets/js/11.770642f2.js"><link rel="prefetch" href="/assets/js/110.cf3d973c.js"><link rel="prefetch" href="/assets/js/111.f985889a.js"><link rel="prefetch" href="/assets/js/112.ad614f41.js"><link rel="prefetch" href="/assets/js/113.f666653c.js"><link rel="prefetch" href="/assets/js/114.c6c3f384.js"><link rel="prefetch" href="/assets/js/115.e51d3c2f.js"><link rel="prefetch" href="/assets/js/116.4f4b39f5.js"><link rel="prefetch" href="/assets/js/117.99352e11.js"><link rel="prefetch" href="/assets/js/118.c6ae6572.js"><link rel="prefetch" href="/assets/js/119.4ccbe778.js"><link rel="prefetch" href="/assets/js/12.042a92ff.js"><link rel="prefetch" href="/assets/js/120.edda1c4f.js"><link rel="prefetch" href="/assets/js/121.30a638ed.js"><link rel="prefetch" href="/assets/js/122.6efcefb1.js"><link rel="prefetch" href="/assets/js/123.91e6665b.js"><link rel="prefetch" href="/assets/js/124.f27e3d7e.js"><link rel="prefetch" href="/assets/js/125.c75712d5.js"><link rel="prefetch" href="/assets/js/126.ed756cce.js"><link rel="prefetch" href="/assets/js/127.2f06c74c.js"><link rel="prefetch" href="/assets/js/128.d5f6f30e.js"><link rel="prefetch" href="/assets/js/129.508b7eed.js"><link rel="prefetch" href="/assets/js/13.b5280c37.js"><link rel="prefetch" href="/assets/js/130.dc05f9aa.js"><link rel="prefetch" href="/assets/js/131.e0ba69b1.js"><link rel="prefetch" href="/assets/js/132.d79bcaa4.js"><link rel="prefetch" href="/assets/js/133.34acc01a.js"><link rel="prefetch" href="/assets/js/134.dabf64d5.js"><link rel="prefetch" href="/assets/js/135.ad90c915.js"><link rel="prefetch" href="/assets/js/136.dbb0074f.js"><link rel="prefetch" href="/assets/js/137.284ad365.js"><link rel="prefetch" href="/assets/js/138.a4b6856f.js"><link rel="prefetch" href="/assets/js/139.c9c1e20f.js"><link rel="prefetch" href="/assets/js/14.df02ba38.js"><link rel="prefetch" href="/assets/js/140.8b0a9269.js"><link rel="prefetch" href="/assets/js/141.9c7759c5.js"><link rel="prefetch" href="/assets/js/142.a4201a82.js"><link rel="prefetch" href="/assets/js/143.d7da6e8c.js"><link rel="prefetch" href="/assets/js/144.5e48e65d.js"><link rel="prefetch" href="/assets/js/145.a0e2633c.js"><link rel="prefetch" href="/assets/js/146.3c775f9b.js"><link rel="prefetch" href="/assets/js/147.22add89a.js"><link rel="prefetch" href="/assets/js/148.cfde1009.js"><link rel="prefetch" href="/assets/js/149.ffc835b5.js"><link rel="prefetch" href="/assets/js/15.fbdfc4ee.js"><link rel="prefetch" href="/assets/js/150.406c4b20.js"><link rel="prefetch" href="/assets/js/151.b2040eea.js"><link rel="prefetch" href="/assets/js/152.7bc65661.js"><link rel="prefetch" href="/assets/js/153.1d7c65e3.js"><link rel="prefetch" href="/assets/js/154.1309de49.js"><link rel="prefetch" href="/assets/js/155.81d3ee1f.js"><link rel="prefetch" href="/assets/js/156.154a4ef2.js"><link rel="prefetch" href="/assets/js/16.e5eb6147.js"><link rel="prefetch" href="/assets/js/17.57853c4a.js"><link rel="prefetch" href="/assets/js/18.cb9d7518.js"><link rel="prefetch" href="/assets/js/19.f354dc47.js"><link rel="prefetch" href="/assets/js/2.570d8a23.js"><link rel="prefetch" href="/assets/js/20.b5af7fad.js"><link rel="prefetch" href="/assets/js/21.0b1928fe.js"><link rel="prefetch" href="/assets/js/23.29c3f366.js"><link rel="prefetch" href="/assets/js/24.6f596516.js"><link rel="prefetch" href="/assets/js/25.14067b60.js"><link rel="prefetch" href="/assets/js/26.74ba4989.js"><link rel="prefetch" href="/assets/js/27.13d60edd.js"><link rel="prefetch" href="/assets/js/28.9523cb32.js"><link rel="prefetch" href="/assets/js/29.8ec842e9.js"><link rel="prefetch" href="/assets/js/3.3fb3d2e0.js"><link rel="prefetch" href="/assets/js/30.805597a8.js"><link rel="prefetch" href="/assets/js/31.831b195d.js"><link rel="prefetch" href="/assets/js/32.063c672d.js"><link rel="prefetch" href="/assets/js/33.6d93fac3.js"><link rel="prefetch" href="/assets/js/34.56e8263c.js"><link rel="prefetch" href="/assets/js/35.dbe688bb.js"><link rel="prefetch" href="/assets/js/36.dc5af2c1.js"><link rel="prefetch" href="/assets/js/37.0a7494f6.js"><link rel="prefetch" href="/assets/js/38.fe4fc171.js"><link rel="prefetch" href="/assets/js/39.f5ed5e92.js"><link rel="prefetch" href="/assets/js/4.2c405ec8.js"><link rel="prefetch" href="/assets/js/40.fe7e2714.js"><link rel="prefetch" href="/assets/js/41.30b0811d.js"><link rel="prefetch" href="/assets/js/42.76f52d62.js"><link rel="prefetch" href="/assets/js/43.e7bb0817.js"><link rel="prefetch" href="/assets/js/44.ead0e883.js"><link rel="prefetch" href="/assets/js/45.235df046.js"><link rel="prefetch" href="/assets/js/46.5f09e829.js"><link rel="prefetch" href="/assets/js/47.67116354.js"><link rel="prefetch" href="/assets/js/48.31f34543.js"><link rel="prefetch" href="/assets/js/49.10b5ebba.js"><link rel="prefetch" href="/assets/js/5.6f47322c.js"><link rel="prefetch" href="/assets/js/50.c0f0b7f1.js"><link rel="prefetch" href="/assets/js/51.5143f3bf.js"><link rel="prefetch" href="/assets/js/52.eeddfd48.js"><link rel="prefetch" href="/assets/js/53.eb790db5.js"><link rel="prefetch" href="/assets/js/54.8fe5421c.js"><link rel="prefetch" href="/assets/js/55.d8f9004b.js"><link rel="prefetch" href="/assets/js/56.62ac9b92.js"><link rel="prefetch" href="/assets/js/57.a9caec0d.js"><link rel="prefetch" href="/assets/js/58.f93fc522.js"><link rel="prefetch" href="/assets/js/59.a81a03aa.js"><link rel="prefetch" href="/assets/js/6.8c2ea393.js"><link rel="prefetch" href="/assets/js/60.ab782775.js"><link rel="prefetch" href="/assets/js/61.6dd12daf.js"><link rel="prefetch" href="/assets/js/62.76f4b01f.js"><link rel="prefetch" href="/assets/js/63.6f8a4742.js"><link rel="prefetch" href="/assets/js/64.6f8bb1fa.js"><link rel="prefetch" href="/assets/js/65.4120a44b.js"><link rel="prefetch" href="/assets/js/66.360c2d2b.js"><link rel="prefetch" href="/assets/js/67.26f84d32.js"><link rel="prefetch" href="/assets/js/68.68f45e5e.js"><link rel="prefetch" href="/assets/js/69.e311eb56.js"><link rel="prefetch" href="/assets/js/7.6762b2d7.js"><link rel="prefetch" href="/assets/js/70.cea82674.js"><link rel="prefetch" href="/assets/js/71.783ddcf7.js"><link rel="prefetch" href="/assets/js/72.e5467385.js"><link rel="prefetch" href="/assets/js/73.b8fb681b.js"><link rel="prefetch" href="/assets/js/74.1bae37db.js"><link rel="prefetch" href="/assets/js/75.024387e5.js"><link rel="prefetch" href="/assets/js/76.a8e53010.js"><link rel="prefetch" href="/assets/js/77.8c55500a.js"><link rel="prefetch" href="/assets/js/78.7ce90bf5.js"><link rel="prefetch" href="/assets/js/79.ef71713f.js"><link rel="prefetch" href="/assets/js/8.788a6364.js"><link rel="prefetch" href="/assets/js/80.acad589d.js"><link rel="prefetch" href="/assets/js/81.02670d10.js"><link rel="prefetch" href="/assets/js/82.53b7b1ac.js"><link rel="prefetch" href="/assets/js/83.99eb8581.js"><link rel="prefetch" href="/assets/js/84.d1535ce3.js"><link rel="prefetch" href="/assets/js/85.fe2b7de9.js"><link rel="prefetch" href="/assets/js/86.41850272.js"><link rel="prefetch" href="/assets/js/87.1cdc6df9.js"><link rel="prefetch" href="/assets/js/88.01bf3461.js"><link rel="prefetch" href="/assets/js/89.17c69819.js"><link rel="prefetch" href="/assets/js/9.3813842d.js"><link rel="prefetch" href="/assets/js/90.f6ae7e35.js"><link rel="prefetch" href="/assets/js/91.507bc284.js"><link rel="prefetch" href="/assets/js/92.90551782.js"><link rel="prefetch" href="/assets/js/93.dc442d78.js"><link rel="prefetch" href="/assets/js/94.315f4e94.js"><link rel="prefetch" href="/assets/js/95.ccd6c6bf.js"><link rel="prefetch" href="/assets/js/96.0c6d89d0.js"><link rel="prefetch" href="/assets/js/97.1a9f10a9.js"><link rel="prefetch" href="/assets/js/98.43be3caa.js"><link rel="prefetch" href="/assets/js/99.54c8207b.js">
    <link rel="stylesheet" href="/assets/css/0.styles.0dbae9ec.css">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container"><header class="navbar"><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/" class="home-link router-link-active"><!----> <span class="site-name">whoway</span></a> <div class="links" style="max-width:nullpx;"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title">🎓Coding</span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/00.Coding/TheBeautyOfProgramming/" class="nav-link">🔖编程之美题解</a></li><li class="dropdown-item"><!----> <a href="/00.Coding/CodeWarehouse/" class="nav-link">🔖代码意识流</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title">🚀语言</span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/01.Language/Overview/" class="nav-link">🔖概述</a></li><li class="dropdown-item"><!----> <a href="/01.Language/C/" class="nav-link router-link-active">⭐️C</a></li><li class="dropdown-item"><!----> <a href="/01.Language/Cpp/" class="nav-link">🚀C++</a></li><li class="dropdown-item"><!----> <a href="/01.Language/Java/" class="nav-link">☕️Java</a></li><li class="dropdown-item"><!----> <a href="/01.Language/Python/" class="nav-link">🧩Python3</a></li></ul></div></div><div class="nav-item"><a href="/02.Hardware/" class="nav-link">✔️硬件基础</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title">⭐️软件基础</span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/03.Software/01.DataStructureAndAlgorithm/" class="nav-link">🐾数据结构和算法</a></li><li class="dropdown-item"><!----> <a href="/03.Software/02.OS/" class="nav-link">💻操作系统</a></li><li class="dropdown-item"><!----> <a href="/03.Software/03.Net/" class="nav-link">☁️计算机网络</a></li><li class="dropdown-item"><!----> <a href="/03.Software/04.SE/" class="nav-link">✅软件工程</a></li></ul></div></div><div class="nav-item"><a href="/04.Database/" class="nav-link">🎨数据库</a></div><div class="nav-item"><a href="/05.Engineer/" class="nav-link">🔖学术/工程</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title">⚙️工具</span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/06.Tools/01.employment/" class="nav-link">🔖求职</a></li><li class="dropdown-item"><!----> <a href="/06.Tools/02.efficiency/" class="nav-link">🚀效能</a></li><li class="dropdown-item"><!----> <a href="/06.Tools/03.windows/" class="nav-link">⚙️Windows</a></li><li class="dropdown-item"><!----> <a href="/06.Tools/04.design/" class="nav-link">🧩设计</a></li><li class="dropdown-item"><!----> <a href="/06.Tools/05.linux/" class="nav-link">🐉Linux</a></li></ul></div></div><div class="nav-item"><a href="https://github.com/whoway" target="_blank" rel="noopener noreferrer" class="nav-link external">
  GitHub
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></div> <!----></nav></div></header> <div class="sidebar-mask"></div> <div class="sidebar"><nav class="nav-links"><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title">🎓Coding</span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/00.Coding/TheBeautyOfProgramming/" class="nav-link">🔖编程之美题解</a></li><li class="dropdown-item"><!----> <a href="/00.Coding/CodeWarehouse/" class="nav-link">🔖代码意识流</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title">🚀语言</span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/01.Language/Overview/" class="nav-link">🔖概述</a></li><li class="dropdown-item"><!----> <a href="/01.Language/C/" class="nav-link router-link-active">⭐️C</a></li><li class="dropdown-item"><!----> <a href="/01.Language/Cpp/" class="nav-link">🚀C++</a></li><li class="dropdown-item"><!----> <a href="/01.Language/Java/" class="nav-link">☕️Java</a></li><li class="dropdown-item"><!----> <a href="/01.Language/Python/" class="nav-link">🧩Python3</a></li></ul></div></div><div class="nav-item"><a href="/02.Hardware/" class="nav-link">✔️硬件基础</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title">⭐️软件基础</span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/03.Software/01.DataStructureAndAlgorithm/" class="nav-link">🐾数据结构和算法</a></li><li class="dropdown-item"><!----> <a href="/03.Software/02.OS/" class="nav-link">💻操作系统</a></li><li class="dropdown-item"><!----> <a href="/03.Software/03.Net/" class="nav-link">☁️计算机网络</a></li><li class="dropdown-item"><!----> <a href="/03.Software/04.SE/" class="nav-link">✅软件工程</a></li></ul></div></div><div class="nav-item"><a href="/04.Database/" class="nav-link">🎨数据库</a></div><div class="nav-item"><a href="/05.Engineer/" class="nav-link">🔖学术/工程</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title">⚙️工具</span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/06.Tools/01.employment/" class="nav-link">🔖求职</a></li><li class="dropdown-item"><!----> <a href="/06.Tools/02.efficiency/" class="nav-link">🚀效能</a></li><li class="dropdown-item"><!----> <a href="/06.Tools/03.windows/" class="nav-link">⚙️Windows</a></li><li class="dropdown-item"><!----> <a href="/06.Tools/04.design/" class="nav-link">🧩设计</a></li><li class="dropdown-item"><!----> <a href="/06.Tools/05.linux/" class="nav-link">🐉Linux</a></li></ul></div></div><div class="nav-item"><a href="https://github.com/whoway" target="_blank" rel="noopener noreferrer" class="nav-link external">
  GitHub
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></div> <!----></nav>  <ul class="sidebar-links"><li><div class="sidebar-group first"><p class="sidebar-heading open"><span>C和C++运算符规则记忆</span> <!----></p> <ul class="sidebar-group-items"><li><a href="/01.Language/C/%E6%A0%B8%E5%BF%83%E7%9F%A5%E8%AF%86/02.C%E5%92%8CCplusplus%E4%BC%98%E5%85%88%E7%BA%A7%E5%92%8C%E7%BB%93%E5%90%88%E6%80%A7%E8%AE%B0%E5%BF%86.html#✅01-c语言优先级和结合性记忆" class="sidebar-link">✅01.C语言优先级和结合性记忆</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/01.Language/C/%E6%A0%B8%E5%BF%83%E7%9F%A5%E8%AF%86/02.C%E5%92%8CCplusplus%E4%BC%98%E5%85%88%E7%BA%A7%E5%92%8C%E7%BB%93%E5%90%88%E6%80%A7%E8%AE%B0%E5%BF%86.html#_1-1-前述" class="sidebar-link">1.1.前述</a></li><li class="sidebar-sub-header"><a href="/01.Language/C/%E6%A0%B8%E5%BF%83%E7%9F%A5%E8%AF%86/02.C%E5%92%8CCplusplus%E4%BC%98%E5%85%88%E7%BA%A7%E5%92%8C%E7%BB%93%E5%90%88%E6%80%A7%E8%AE%B0%E5%BF%86.html#_1-2-优先级记忆" class="sidebar-link">1.2.优先级记忆</a></li><li class="sidebar-sub-header"><a href="/01.Language/C/%E6%A0%B8%E5%BF%83%E7%9F%A5%E8%AF%86/02.C%E5%92%8CCplusplus%E4%BC%98%E5%85%88%E7%BA%A7%E5%92%8C%E7%BB%93%E5%90%88%E6%80%A7%E8%AE%B0%E5%BF%86.html#_1-3-结合性记忆" class="sidebar-link">1.3.结合性记忆</a></li><li class="sidebar-sub-header"><a href="/01.Language/C/%E6%A0%B8%E5%BF%83%E7%9F%A5%E8%AF%86/02.C%E5%92%8CCplusplus%E4%BC%98%E5%85%88%E7%BA%A7%E5%92%8C%E7%BB%93%E5%90%88%E6%80%A7%E8%AE%B0%E5%BF%86.html#_1-4-“最大贪婪”规则" class="sidebar-link">1.4.“最大贪婪”规则</a></li><li class="sidebar-sub-header"><a href="/01.Language/C/%E6%A0%B8%E5%BF%83%E7%9F%A5%E8%AF%86/02.C%E5%92%8CCplusplus%E4%BC%98%E5%85%88%E7%BA%A7%E5%92%8C%E7%BB%93%E5%90%88%E6%80%A7%E8%AE%B0%E5%BF%86.html#_1-4-用法举例" class="sidebar-link">1.4.用法举例</a></li><li class="sidebar-sub-header"><a href="/01.Language/C/%E6%A0%B8%E5%BF%83%E7%9F%A5%E8%AF%86/02.C%E5%92%8CCplusplus%E4%BC%98%E5%85%88%E7%BA%A7%E5%92%8C%E7%BB%93%E5%90%88%E6%80%A7%E8%AE%B0%E5%BF%86.html#（1）记忆第一优先级中的和第二优先级" class="sidebar-link">（1）记忆第一优先级中的和第二优先级</a></li><li class="sidebar-sub-header"><a href="/01.Language/C/%E6%A0%B8%E5%BF%83%E7%9F%A5%E8%AF%86/02.C%E5%92%8CCplusplus%E4%BC%98%E5%85%88%E7%BA%A7%E5%92%8C%E7%BB%93%E5%90%88%E6%80%A7%E8%AE%B0%E5%BF%86.html#（2）比格基地笔试题" class="sidebar-link">（2）比格基地笔试题</a></li><li class="sidebar-sub-header"><a href="/01.Language/C/%E6%A0%B8%E5%BF%83%E7%9F%A5%E8%AF%86/02.C%E5%92%8CCplusplus%E4%BC%98%E5%85%88%E7%BA%A7%E5%92%8C%E7%BB%93%E5%90%88%E6%80%A7%E8%AE%B0%E5%BF%86.html#（3）360公司笔试题" class="sidebar-link">（3）360公司笔试题</a></li><li class="sidebar-sub-header"><a href="/01.Language/C/%E6%A0%B8%E5%BF%83%E7%9F%A5%E8%AF%86/02.C%E5%92%8CCplusplus%E4%BC%98%E5%85%88%E7%BA%A7%E5%92%8C%E7%BB%93%E5%90%88%E6%80%A7%E8%AE%B0%E5%BF%86.html#_1-5-分析方法" class="sidebar-link">1.5.分析方法</a></li></ul></li><li><a href="/01.Language/C/%E6%A0%B8%E5%BF%83%E7%9F%A5%E8%AF%86/02.C%E5%92%8CCplusplus%E4%BC%98%E5%85%88%E7%BA%A7%E5%92%8C%E7%BB%93%E5%90%88%E6%80%A7%E8%AE%B0%E5%BF%86.html#✅02-c-优先级和结合性记忆" class="sidebar-link">✅02.C++优先级和结合性记忆</a><ul class="sidebar-sub-headers"></ul></li><li><a href="/01.Language/C/%E6%A0%B8%E5%BF%83%E7%9F%A5%E8%AF%86/02.C%E5%92%8CCplusplus%E4%BC%98%E5%85%88%E7%BA%A7%E5%92%8C%E7%BB%93%E5%90%88%E6%80%A7%E8%AE%B0%E5%BF%86.html#✅03-纯c语言的典例训练" class="sidebar-link">✅03.纯C语言的典例训练</a><ul class="sidebar-sub-headers"></ul></li><li><a href="/01.Language/C/%E6%A0%B8%E5%BF%83%E7%9F%A5%E8%AF%86/02.C%E5%92%8CCplusplus%E4%BC%98%E5%85%88%E7%BA%A7%E5%92%8C%E7%BB%93%E5%90%88%E6%80%A7%E8%AE%B0%E5%BF%86.html#一、做题步骤" class="sidebar-link">一、做题步骤</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/01.Language/C/%E6%A0%B8%E5%BF%83%E7%9F%A5%E8%AF%86/02.C%E5%92%8CCplusplus%E4%BC%98%E5%85%88%E7%BA%A7%E5%92%8C%E7%BB%93%E5%90%88%E6%80%A7%E8%AE%B0%E5%BF%86.html#（1）知识补充" class="sidebar-link">（1）知识补充</a></li><li class="sidebar-sub-header"><a href="/01.Language/C/%E6%A0%B8%E5%BF%83%E7%9F%A5%E8%AF%86/02.C%E5%92%8CCplusplus%E4%BC%98%E5%85%88%E7%BA%A7%E5%92%8C%E7%BB%93%E5%90%88%E6%80%A7%E8%AE%B0%E5%BF%86.html#（2）技巧总结" class="sidebar-link">（2）技巧总结</a></li><li class="sidebar-sub-header"><a href="/01.Language/C/%E6%A0%B8%E5%BF%83%E7%9F%A5%E8%AF%86/02.C%E5%92%8CCplusplus%E4%BC%98%E5%85%88%E7%BA%A7%E5%92%8C%E7%BB%93%E5%90%88%E6%80%A7%E8%AE%B0%E5%BF%86.html#（3）词法解析-优先级-结合性" class="sidebar-link">（3）词法解析+优先级+结合性</a></li></ul></li><li><a href="/01.Language/C/%E6%A0%B8%E5%BF%83%E7%9F%A5%E8%AF%86/02.C%E5%92%8CCplusplus%E4%BC%98%E5%85%88%E7%BA%A7%E5%92%8C%E7%BB%93%E5%90%88%E6%80%A7%E8%AE%B0%E5%BF%86.html#二、典型例题训练" class="sidebar-link">二、典型例题训练</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/01.Language/C/%E6%A0%B8%E5%BF%83%E7%9F%A5%E8%AF%86/02.C%E5%92%8CCplusplus%E4%BC%98%E5%85%88%E7%BA%A7%E5%92%8C%E7%BB%93%E5%90%88%E6%80%A7%E8%AE%B0%E5%BF%86.html#例题1" class="sidebar-link">例题1</a></li><li class="sidebar-sub-header"><a href="/01.Language/C/%E6%A0%B8%E5%BF%83%E7%9F%A5%E8%AF%86/02.C%E5%92%8CCplusplus%E4%BC%98%E5%85%88%E7%BA%A7%E5%92%8C%E7%BB%93%E5%90%88%E6%80%A7%E8%AE%B0%E5%BF%86.html#例题2" class="sidebar-link">例题2</a></li><li class="sidebar-sub-header"><a href="/01.Language/C/%E6%A0%B8%E5%BF%83%E7%9F%A5%E8%AF%86/02.C%E5%92%8CCplusplus%E4%BC%98%E5%85%88%E7%BA%A7%E5%92%8C%E7%BB%93%E5%90%88%E6%80%A7%E8%AE%B0%E5%BF%86.html#例题3" class="sidebar-link">例题3</a></li><li class="sidebar-sub-header"><a href="/01.Language/C/%E6%A0%B8%E5%BF%83%E7%9F%A5%E8%AF%86/02.C%E5%92%8CCplusplus%E4%BC%98%E5%85%88%E7%BA%A7%E5%92%8C%E7%BB%93%E5%90%88%E6%80%A7%E8%AE%B0%E5%BF%86.html#例题4" class="sidebar-link">例题4</a></li><li class="sidebar-sub-header"><a href="/01.Language/C/%E6%A0%B8%E5%BF%83%E7%9F%A5%E8%AF%86/02.C%E5%92%8CCplusplus%E4%BC%98%E5%85%88%E7%BA%A7%E5%92%8C%E7%BB%93%E5%90%88%E6%80%A7%E8%AE%B0%E5%BF%86.html#例题5" class="sidebar-link">例题5</a></li><li class="sidebar-sub-header"><a href="/01.Language/C/%E6%A0%B8%E5%BF%83%E7%9F%A5%E8%AF%86/02.C%E5%92%8CCplusplus%E4%BC%98%E5%85%88%E7%BA%A7%E5%92%8C%E7%BB%93%E5%90%88%E6%80%A7%E8%AE%B0%E5%BF%86.html#例题6" class="sidebar-link">例题6</a></li><li class="sidebar-sub-header"><a href="/01.Language/C/%E6%A0%B8%E5%BF%83%E7%9F%A5%E8%AF%86/02.C%E5%92%8CCplusplus%E4%BC%98%E5%85%88%E7%BA%A7%E5%92%8C%E7%BB%93%E5%90%88%E6%80%A7%E8%AE%B0%E5%BF%86.html#例题7" class="sidebar-link">例题7</a></li><li class="sidebar-sub-header"><a href="/01.Language/C/%E6%A0%B8%E5%BF%83%E7%9F%A5%E8%AF%86/02.C%E5%92%8CCplusplus%E4%BC%98%E5%85%88%E7%BA%A7%E5%92%8C%E7%BB%93%E5%90%88%E6%80%A7%E8%AE%B0%E5%BF%86.html#补充（博客遗漏之处）：" class="sidebar-link">补充（博客遗漏之处）：</a></li><li class="sidebar-sub-header"><a href="/01.Language/C/%E6%A0%B8%E5%BF%83%E7%9F%A5%E8%AF%86/02.C%E5%92%8CCplusplus%E4%BC%98%E5%85%88%E7%BA%A7%E5%92%8C%E7%BB%93%E5%90%88%E6%80%A7%E8%AE%B0%E5%BF%86.html#例题组别（关于逻辑运算返回值）" class="sidebar-link">例题组别（关于逻辑运算返回值）</a></li></ul></li><li><a href="/01.Language/C/%E6%A0%B8%E5%BF%83%E7%9F%A5%E8%AF%86/02.C%E5%92%8CCplusplus%E4%BC%98%E5%85%88%E7%BA%A7%E5%92%8C%E7%BB%93%E5%90%88%E6%80%A7%E8%AE%B0%E5%BF%86.html#三、题库" class="sidebar-link">三、题库</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/01.Language/C/%E6%A0%B8%E5%BF%83%E7%9F%A5%E8%AF%86/02.C%E5%92%8CCplusplus%E4%BC%98%E5%85%88%E7%BA%A7%E5%92%8C%E7%BB%93%E5%90%88%E6%80%A7%E8%AE%B0%E5%BF%86.html#例1" class="sidebar-link">例1</a></li><li class="sidebar-sub-header"><a href="/01.Language/C/%E6%A0%B8%E5%BF%83%E7%9F%A5%E8%AF%86/02.C%E5%92%8CCplusplus%E4%BC%98%E5%85%88%E7%BA%A7%E5%92%8C%E7%BB%93%E5%90%88%E6%80%A7%E8%AE%B0%E5%BF%86.html#例2" class="sidebar-link">例2</a></li><li class="sidebar-sub-header"><a href="/01.Language/C/%E6%A0%B8%E5%BF%83%E7%9F%A5%E8%AF%86/02.C%E5%92%8CCplusplus%E4%BC%98%E5%85%88%E7%BA%A7%E5%92%8C%E7%BB%93%E5%90%88%E6%80%A7%E8%AE%B0%E5%BF%86.html#例3" class="sidebar-link">例3</a></li></ul></li><li><a href="/01.Language/C/%E6%A0%B8%E5%BF%83%E7%9F%A5%E8%AF%86/02.C%E5%92%8CCplusplus%E4%BC%98%E5%85%88%E7%BA%A7%E5%92%8C%E7%BB%93%E5%90%88%E6%80%A7%E8%AE%B0%E5%BF%86.html#四、似乎是方法之外的题目" class="sidebar-link">四、似乎是方法之外的题目</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/01.Language/C/%E6%A0%B8%E5%BF%83%E7%9F%A5%E8%AF%86/02.C%E5%92%8CCplusplus%E4%BC%98%E5%85%88%E7%BA%A7%E5%92%8C%E7%BB%93%E5%90%88%E6%80%A7%E8%AE%B0%E5%BF%86.html#（1），逗号分隔非平行宇宙——一般情况" class="sidebar-link">（1），逗号分隔非平行宇宙——一般情况</a></li><li class="sidebar-sub-header"><a href="/01.Language/C/%E6%A0%B8%E5%BF%83%E7%9F%A5%E8%AF%86/02.C%E5%92%8CCplusplus%E4%BC%98%E5%85%88%E7%BA%A7%E5%92%8C%E7%BB%93%E5%90%88%E6%80%A7%E8%AE%B0%E5%BF%86.html#（2），逗号分隔非平行宇宙——特殊情况" class="sidebar-link">（2），逗号分隔非平行宇宙——特殊情况</a></li></ul></li><li><a href="/01.Language/C/%E6%A0%B8%E5%BF%83%E7%9F%A5%E8%AF%86/02.C%E5%92%8CCplusplus%E4%BC%98%E5%85%88%E7%BA%A7%E5%92%8C%E7%BB%93%E5%90%88%E6%80%A7%E8%AE%B0%E5%BF%86.html#五、相似却不是这个考点的题目" class="sidebar-link">五、相似却不是这个考点的题目</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/01.Language/C/%E6%A0%B8%E5%BF%83%E7%9F%A5%E8%AF%86/02.C%E5%92%8CCplusplus%E4%BC%98%E5%85%88%E7%BA%A7%E5%92%8C%E7%BB%93%E5%90%88%E6%80%A7%E8%AE%B0%E5%BF%86.html#（1）例1" class="sidebar-link">（1）例1</a></li><li class="sidebar-sub-header"><a href="/01.Language/C/%E6%A0%B8%E5%BF%83%E7%9F%A5%E8%AF%86/02.C%E5%92%8CCplusplus%E4%BC%98%E5%85%88%E7%BA%A7%E5%92%8C%E7%BB%93%E5%90%88%E6%80%A7%E8%AE%B0%E5%BF%86.html#（2）例2（你真的搞懂了我编的口诀？）" class="sidebar-link">（2）例2（你真的搞懂了我编的口诀？）</a></li><li class="sidebar-sub-header"><a href="/01.Language/C/%E6%A0%B8%E5%BF%83%E7%9F%A5%E8%AF%86/02.C%E5%92%8CCplusplus%E4%BC%98%E5%85%88%E7%BA%A7%E5%92%8C%E7%BB%93%E5%90%88%E6%80%A7%E8%AE%B0%E5%BF%86.html#（3）你以为我是在考优先级" class="sidebar-link">（3）你以为我是在考优先级?</a></li><li class="sidebar-sub-header"><a href="/01.Language/C/%E6%A0%B8%E5%BF%83%E7%9F%A5%E8%AF%86/02.C%E5%92%8CCplusplus%E4%BC%98%E5%85%88%E7%BA%A7%E5%92%8C%E7%BB%93%E5%90%88%E6%80%A7%E8%AE%B0%E5%BF%86.html#（4）（易错！！）这次我真的在考“优先级”，顺路考“短路原则”（短路优先原则的逆袭）" class="sidebar-link">（4）（易错！！）这次我真的在考“优先级”，顺路考“短路原则”（短路优先原则的逆袭）</a></li><li class="sidebar-sub-header"><a href="/01.Language/C/%E6%A0%B8%E5%BF%83%E7%9F%A5%E8%AF%86/02.C%E5%92%8CCplusplus%E4%BC%98%E5%85%88%E7%BA%A7%E5%92%8C%E7%BB%93%E5%90%88%E6%80%A7%E8%AE%B0%E5%BF%86.html#（5）结合性和指针结合" class="sidebar-link">（5）结合性和指针结合</a></li><li class="sidebar-sub-header"><a href="/01.Language/C/%E6%A0%B8%E5%BF%83%E7%9F%A5%E8%AF%86/02.C%E5%92%8CCplusplus%E4%BC%98%E5%85%88%E7%BA%A7%E5%92%8C%E7%BB%93%E5%90%88%E6%80%A7%E8%AE%B0%E5%BF%86.html#（6）优先级和类型升级结合" class="sidebar-link">（6）优先级和类型升级结合</a></li><li class="sidebar-sub-header"><a href="/01.Language/C/%E6%A0%B8%E5%BF%83%E7%9F%A5%E8%AF%86/02.C%E5%92%8CCplusplus%E4%BC%98%E5%85%88%E7%BA%A7%E5%92%8C%E7%BB%93%E5%90%88%E6%80%A7%E8%AE%B0%E5%BF%86.html#（7）易错" class="sidebar-link">（7）易错</a></li></ul></li><li><a href="/01.Language/C/%E6%A0%B8%E5%BF%83%E7%9F%A5%E8%AF%86/02.C%E5%92%8CCplusplus%E4%BC%98%E5%85%88%E7%BA%A7%E5%92%8C%E7%BB%93%E5%90%88%E6%80%A7%E8%AE%B0%E5%BF%86.html#六、c-中运算符" class="sidebar-link">六、C++中运算符</a><ul class="sidebar-sub-headers"></ul></li><li><a href="/01.Language/C/%E6%A0%B8%E5%BF%83%E7%9F%A5%E8%AF%86/02.C%E5%92%8CCplusplus%E4%BC%98%E5%85%88%E7%BA%A7%E5%92%8C%E7%BB%93%E5%90%88%E6%80%A7%E8%AE%B0%E5%BF%86.html#七、true和false你真的了解吗？" class="sidebar-link">七、true和false你真的了解吗？</a><ul class="sidebar-sub-headers"></ul></li><li><a href="/01.Language/C/%E6%A0%B8%E5%BF%83%E7%9F%A5%E8%AF%86/02.C%E5%92%8CCplusplus%E4%BC%98%E5%85%88%E7%BA%A7%E5%92%8C%E7%BB%93%E5%90%88%E6%80%A7%E8%AE%B0%E5%BF%86.html#八、sizeof真的是运算符" class="sidebar-link">八、sizeof真的是运算符</a><ul class="sidebar-sub-headers"></ul></li></ul></div></li></ul> </div> <div class="page"> <div class="content"><h1 id="c和c-运算符规则记忆"><a href="#c和c-运算符规则记忆" class="header-anchor">#</a> C和C++运算符规则记忆</h1> <p>[TOC]</p> <h2 id="✅01-c语言优先级和结合性记忆"><a href="#✅01-c语言优先级和结合性记忆" class="header-anchor">#</a> ✅01.C语言优先级和结合性记忆</h2> <h3 id="_1-1-前述"><a href="#_1-1-前述" class="header-anchor">#</a> 1.1.前述</h3> <p><strong>前述</strong>：以前以为，记忆C语言的优先级和结合性就像孔乙己记忆“回”字的四种写法一样有些没必要，对于技术，简洁即美。但以下场景，记忆C语言的优先级结合性还是有一定好处<br> <strong>场景</strong>：</p> <ul><li>记忆一些特定的优先级和结合性，能够帮助从编译器角度来快速识别多级指针和数组指针和函数指针判定指针类型。</li> <li>某些项目的遗留代码中有一些编程风格不好的片段，总是不写括号，遇到就需要查书，对研究别人代码，有一定影响。记忆优先级和结合性，能够降低开发中重构已有代码的难度。</li> <li>有的相关试题中，有考优先级的题目的存在。（考优先级不是目的，而是为了解决那些风格不好的遗留代码）</li> <li>由于编译器语法分析阶段的设计原理，其他语言的优先级也可以在此基础上记忆。
<ul><li>C语言的优先级，再添加上一些C++本身的运算符，则很容易转换到记忆C++的优先级</li> <li>Java的运算符的优先级和C语言相似</li></ul></li></ul> <center>优先级从高到低，分为15级</center> <p><img src="https://cdn.jsdelivr.net/gh/HACV/picture/img/2020_5.28_1.jpg" alt="2020_5.28_1"></p> <p><img src="https://cdn.jsdelivr.net/gh/HACV/picture/img/2020_5.28_2.jpg" alt="2020_5.28_2"></p> <h3 id="_1-2-优先级记忆"><a href="#_1-2-优先级记忆" class="header-anchor">#</a> 1.2.优先级记忆</h3> <ul><li><font style="background:yellow;">初-单-算-移-关        （出箪蒜一罐）</font></li> <li><font style="background:yellow;">位-逻-三-赋-逗        （味落三伏豆）</font></li></ul> <p>//箪—意指古代盛饭用的圆形竹器</p> <blockquote><p><strong>记忆场景</strong>：<br>
每年三伏天农作时期，要为田间劳作者送饭，送饭者专门用箪盛着食物前往，还专门为其中一个很喜欢吃大蒜的劳作者带了一罐蒜解馋。后来，劳作者吃着发现，今年的三伏天的黄豆也格外美味。</p></blockquote> <p>解释：</p> <ul><li>初：初级运算符</li> <li>单：单目运算符</li> <li>算：算数运算符（包含2个优先级）</li> <li>移：移位运算符</li> <li>关：关系运算符（包含2个优先级）</li> <li>位：位运算（除去，位运算中的单目运算符~ 包含3个优先级）</li> <li>逻：逻辑运算符（包含2个优先级）</li> <li>三：三目运算符</li> <li>赋：赋值运算符</li> <li>逗：逗号运算符</li></ul> <h3 id="_1-3-结合性记忆"><a href="#_1-3-结合性记忆" class="header-anchor">#</a> 1.3.结合性记忆</h3> <p><font style="background:yellow;">单三赋    从右左</font></p> <ul><li>除以上规则以外,还有一点。</li> <li>标准的C语言编译器对运算符的解析遵循“最大贪婪”规则。</li></ul> <h3 id="_1-4-“最大贪婪”规则"><a href="#_1-4-“最大贪婪”规则" class="header-anchor">#</a> 1.4.“最大贪婪”规则</h3> <p>当C语言编译器对源程序进行词法分析时，如果运算符的下一个符号还是运算符，并且能和前一个运算符构成一个新的合法运算符时，编译器的词法分析器必须将其解析为两个运算符符号构成的新的运算符</p> <p>举一个没太大实际意义的例子来辅证，例如: x=z+++y;<br>
是按照x=z+（++y）;来计算，还是按照x=（z++）+y;来计算呢?<br>
根据C编译器的“最大贪婪”规则,是按照x=（z++）+y;来计算，而不是按照x=z+（++y）来计算
可以验证</p> <div class="language-cpp line-numbers-mode"><pre class="language-cpp"><code><span class="token keyword">int</span> z<span class="token operator">=</span><span class="token number">3</span><span class="token punctuation">,</span>y<span class="token operator">=</span><span class="token number">5</span><span class="token punctuation">;</span>
<span class="token keyword">int</span> x<span class="token punctuation">;</span>
x<span class="token operator">=</span>z<span class="token operator">++</span><span class="token operator">+</span>y<span class="token punctuation">;</span>
<span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;%d\n&quot;</span><span class="token punctuation">,</span>x<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token comment">//输出结果为8，而不是9</span>
<span class="token comment">//考点：C编译器的“最大贪婪”规则</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br></div></div><h3 id="_1-4-用法举例"><a href="#_1-4-用法举例" class="header-anchor">#</a> 1.4.用法举例</h3> <h3 id="（1）记忆第一优先级中的和第二优先级"><a href="#（1）记忆第一优先级中的和第二优先级" class="header-anchor">#</a> （1）记忆第一优先级中的和第二优先级</h3> <div class="language-cpp line-numbers-mode"><pre class="language-cpp"><code><span class="token keyword">int</span> <span class="token punctuation">(</span><span class="token operator">*</span>p<span class="token punctuation">)</span><span class="token punctuation">[</span><span class="token number">3</span><span class="token punctuation">]</span><span class="token punctuation">;</span>    <span class="token comment">//这是一个数组指针，指向的类型是int (*)[3]</span>
<span class="token keyword">int</span> <span class="token operator">*</span>p<span class="token punctuation">[</span><span class="token number">3</span><span class="token punctuation">]</span><span class="token punctuation">;</span>    <span class="token comment">//这是一个指针数组，里面的是int *类型的指针</span>
<span class="token keyword">int</span> <span class="token operator">*</span><span class="token operator">*</span> p<span class="token punctuation">;</span>    <span class="token comment">//这是一个二级指针，指向的类型是int *</span>
<span class="token keyword">int</span> <span class="token punctuation">(</span><span class="token operator">*</span>p<span class="token punctuation">)</span><span class="token punctuation">(</span><span class="token keyword">int</span> <span class="token punctuation">,</span><span class="token keyword">int</span><span class="token punctuation">)</span><span class="token punctuation">;</span>  <span class="token comment">//这是一个函数指针，指向的类型是int (*)(int,int)</span>
<span class="token keyword">int</span> <span class="token operator">*</span><span class="token function">p</span><span class="token punctuation">(</span><span class="token keyword">int</span> <span class="token punctuation">,</span><span class="token keyword">int</span><span class="token punctuation">)</span><span class="token punctuation">;</span>    <span class="token comment">//这是一个返回值为指针的函数</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br></div></div><h3 id="（2）比格基地笔试题"><a href="#（2）比格基地笔试题" class="header-anchor">#</a> （2）比格基地笔试题</h3> <div class="language-cpp line-numbers-mode"><pre class="language-cpp"><code><span class="token comment">//以下程序的k最终值是：</span>
<span class="token keyword">int</span> i <span class="token operator">=</span> <span class="token number">10</span><span class="token punctuation">;</span>
<span class="token keyword">int</span> j <span class="token operator">=</span> <span class="token number">20</span><span class="token punctuation">;</span>
<span class="token keyword">int</span> k <span class="token operator">=</span> <span class="token number">3</span><span class="token punctuation">;</span>
k <span class="token operator">*=</span> i <span class="token operator">+</span> j<span class="token punctuation">;</span>
<span class="token comment">//答:90</span>
<span class="token comment">//解释  =是赋值运算符 *=是赋值运算符  +是算数运算符 </span>
<span class="token comment">//“出箪蒜一罐,味落三伏豆”知，算数运算符优先级高，先算i+j</span>
<span class="token comment">//考点：编程语言的优先级</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br></div></div><h3 id="（3）360公司笔试题"><a href="#（3）360公司笔试题" class="header-anchor">#</a> （3）360公司笔试题</h3> <div class="language-cpp line-numbers-mode"><pre class="language-cpp"><code><span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span> <span class="token string">&lt;stdio.h&gt;</span></span>
<span class="token keyword">int</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token punctuation">{</span> 
	<span class="token keyword">int</span> i<span class="token punctuation">,</span> j<span class="token punctuation">,</span> m<span class="token operator">=</span><span class="token number">6</span><span class="token punctuation">,</span>n<span class="token operator">=</span><span class="token number">4</span><span class="token punctuation">,</span>  <span class="token operator">*</span>p<span class="token operator">=</span><span class="token operator">&amp;</span>n<span class="token punctuation">,</span> <span class="token operator">*</span>q<span class="token operator">=</span><span class="token operator">&amp;</span>m<span class="token punctuation">;</span>
	<span class="token comment">//“出箪蒜一罐,味落三伏豆”知,关系运算符==的优先级比赋值运算符=高，知i=0</span>
	i<span class="token operator">=</span>p<span class="token operator">==</span><span class="token operator">&amp;</span>m<span class="token punctuation">;</span>	
	<span class="token comment">//(-*p)中，-和*都是单目运算符，结合性是“单三赋，从右左”，所以，相当于(-n)</span>
	j<span class="token operator">=</span><span class="token punctuation">(</span><span class="token operator">-</span><span class="token operator">*</span>p<span class="token punctuation">)</span><span class="token operator">/</span><span class="token punctuation">(</span><span class="token operator">*</span>q<span class="token punctuation">)</span><span class="token operator">+</span><span class="token number">7</span><span class="token punctuation">;</span>
	<span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;i=%d,j=%d\n&quot;</span><span class="token punctuation">,</span> i<span class="token punctuation">,</span>j<span class="token punctuation">)</span><span class="token punctuation">;</span>
	<span class="token keyword">return</span> <span class="token number">0</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
<span class="token comment">//输出为 i=0,j=7</span>
<span class="token comment">//考点：编程语言的优先级,结合性</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br></div></div><h3 id="_1-5-分析方法"><a href="#_1-5-分析方法" class="header-anchor">#</a> 1.5.分析方法</h3> <p>1、借助“最大贪婪”规则进行“词法分析”<br>
2、利用优先级进行分析词义</p> <h2 id="✅02-c-优先级和结合性记忆"><a href="#✅02-c-优先级和结合性记忆" class="header-anchor">#</a> ✅02.C++优先级和结合性记忆</h2> <h2 id="✅03-纯c语言的典例训练"><a href="#✅03-纯c语言的典例训练" class="header-anchor">#</a> ✅03.纯C语言的典例训练</h2> <ul><li>author：HACV</li></ul> <p>[TOC]</p> <h2 id="一、做题步骤"><a href="#一、做题步骤" class="header-anchor">#</a> 一、做题步骤</h2> <h3 id="（1）知识补充"><a href="#（1）知识补充" class="header-anchor">#</a> （1）知识补充</h3> <p>词法解析之“贪心法”——贪婪原则：
每个符号应该包含尽可能多的字符，从左到右一个字符一个字符地读入，如果该字符可能组成一个符号，那么再读入下一个字符，判断已经读入的两个字符组成的字符串是否可能是一个符号的组成层部分；如果可能，继续读入下一个字符，重复上述判断。（编译器将程序分解成符号（词法解析））</p> <p><a href="https://hacv.gitee.io/2020/05/28/2020-05-28-C_priority_and_associative_memory/" target="_blank" rel="noopener noreferrer">记忆口诀和贪婪原则传送门<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></p> <h3 id="（2）技巧总结"><a href="#（2）技巧总结" class="header-anchor">#</a> （2）技巧总结</h3> <ul><li>1、进行词法分析（贪婪原则）</li> <li>2、进行优先级分析（记忆口诀）</li> <li>3、进行结合性分析（记忆口诀）</li> <li>4、开始做题</li> <li>5、注意事项：
<ul><li>1、单行的数据运算是平行宇宙，i++这样的副作用无法马上显现！</li> <li>2、<code>( , , )</code>这样的格式，返回的是最后一个值，本质是优先级的使用</li> <li>逗号运算符得到的结果都是括号最后一个表达式的值，C选项最后x+y的值应该是16，注意每个选项中的X+1其实是没有意义的，它没有重新赋值给X，所以经过这一步X的值是没有变化的。</li> <li>3、逻辑运算的结果，</li> <li>4、没有逗号表达式的“行”是平行宇宙，副作用不显现，但是“,”分隔的不是平行宇宙，副作用现象会发生
<ul><li>此外，</li></ul></li></ul></li> <li>总结：3步法+2个注意事项</li></ul> <h3 id="（3）词法解析-优先级-结合性"><a href="#（3）词法解析-优先级-结合性" class="header-anchor">#</a> （3）词法解析+优先级+结合性</h3> <ul><li>观察下面现象，为本习题测试目的</li></ul> <div class="language-cpp line-numbers-mode"><pre class="language-cpp"><code><span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span><span class="token string">&lt;bits/stdc++.h&gt;</span></span>
<span class="token keyword">using</span> <span class="token keyword">namespace</span> std<span class="token punctuation">;</span> 

<span class="token keyword">int</span>  <span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token punctuation">{</span>
	<span class="token keyword">int</span> sum<span class="token punctuation">,</span>pad<span class="token punctuation">,</span>temp<span class="token punctuation">;</span>
	sum <span class="token operator">=</span> pad <span class="token operator">=</span> <span class="token number">5</span><span class="token punctuation">;</span>
	temp <span class="token operator">=</span> <span class="token operator">++</span>sum<span class="token punctuation">,</span> temp<span class="token operator">++</span> <span class="token punctuation">,</span> <span class="token operator">++</span>pad<span class="token punctuation">;</span><span class="token comment">//输出7 </span>
	<span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;%d\n&quot;</span><span class="token punctuation">,</span>temp<span class="token punctuation">)</span><span class="token punctuation">;</span> 
   
	sum <span class="token operator">=</span> pad <span class="token operator">=</span> <span class="token number">5</span><span class="token punctuation">;</span>
	temp <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token operator">++</span>sum<span class="token punctuation">,</span> temp<span class="token operator">++</span> <span class="token punctuation">,</span> <span class="token operator">++</span>pad<span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token comment">//输出6 </span>
	<span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;%d\n&quot;</span><span class="token punctuation">,</span>temp<span class="token punctuation">)</span><span class="token punctuation">;</span> 
	
	<span class="token comment">// pAd = + + sum,pAd + +,+ + pad;  //注意观察空格，这个词法解析都通过不了 </span>
	<span class="token keyword">return</span> <span class="token number">0</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>

</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br></div></div><h2 id="二、典型例题训练"><a href="#二、典型例题训练" class="header-anchor">#</a> 二、典型例题训练</h2> <h3 id="例题1"><a href="#例题1" class="header-anchor">#</a> 例题1</h3> <div class="language-cpp line-numbers-mode"><pre class="language-cpp"><code>已知<span class="token keyword">int</span> i<span class="token operator">=</span><span class="token number">1</span><span class="token punctuation">,</span> j<span class="token operator">=</span><span class="token number">2</span><span class="token punctuation">;</span>，则表达式i<span class="token operator">++</span><span class="token operator">+</span>j的值为（ ）
选项：A<span class="token punctuation">.</span><span class="token number">1</span>	B<span class="token punctuation">.</span><span class="token number">2</span>	C<span class="token punctuation">.</span><span class="token number">3</span>	D<span class="token punctuation">.</span><span class="token number">4</span>
答案：D
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><p>解析：</p> <p>1、贪婪原则，知，经过词法解析后变为了</p> <div class="language-cpp line-numbers-mode"><pre class="language-cpp"><code>i<span class="token operator">++</span> <span class="token operator">+</span> j
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>2、优先级，知，初级运算符++高于算术运算符+，等价</p> <div class="language-cpp line-numbers-mode"><pre class="language-cpp"><code>平行宇宙第<span class="token number">1</span>步：<span class="token punctuation">(</span>i<span class="token operator">++</span><span class="token punctuation">)</span> <span class="token operator">+</span> j
平行宇宙第<span class="token number">2</span>步：i<span class="token operator">+</span>j		<span class="token comment">//这个i虽然是经过i++之后的i，但是在“平行宇宙”中副作用暂时不显现</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><p>3、结合性，知</p> <div class="language-cpp line-numbers-mode"><pre class="language-cpp"><code>两者都是从左边到右边
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h3 id="例题2"><a href="#例题2" class="header-anchor">#</a> 例题2</h3> <div class="language-cpp line-numbers-mode"><pre class="language-cpp"><code>a<span class="token operator">=</span><span class="token punctuation">(</span>b<span class="token operator">=</span><span class="token number">4</span><span class="token punctuation">)</span><span class="token operator">+</span><span class="token punctuation">(</span>c<span class="token operator">=</span><span class="token number">6</span><span class="token punctuation">)</span> 是一个合法的赋值表达式。请问这句话的说法是正确的吗？
选项：A<span class="token punctuation">.</span>正确	B<span class="token punctuation">.</span>错误
答案：A
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><p>解析：</p> <p>1、贪婪原则，知，经过词法解析后变为了</p> <div class="language-cpp line-numbers-mode"><pre class="language-cpp"><code>a <span class="token operator">=</span> <span class="token punctuation">(</span>b<span class="token operator">=</span><span class="token number">4</span><span class="token punctuation">)</span> <span class="token operator">+</span> <span class="token punctuation">(</span>c<span class="token operator">=</span><span class="token number">6</span><span class="token punctuation">)</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>2、优先级和结合性，知，（）up + up =</p> <p>3、结合性，知，除了=之外，其他都是从左边到右边</p> <div class="language-cpp line-numbers-mode"><pre class="language-cpp"><code>平行宇宙第<span class="token number">1</span>步：<span class="token punctuation">(</span>b<span class="token operator">=</span><span class="token number">4</span><span class="token punctuation">)</span>
平行宇宙第<span class="token number">2</span>步：<span class="token punctuation">(</span>c<span class="token operator">=</span><span class="token number">6</span><span class="token punctuation">)</span>	
平行宇宙第<span class="token number">3</span>步：a<span class="token operator">=</span>b<span class="token operator">+</span>c，其中由于优先级和结合性，先算<span class="token punctuation">(</span>b<span class="token operator">+</span>c<span class="token punctuation">)</span>
平行宇宙第<span class="token number">4</span>步：a<span class="token operator">=</span><span class="token punctuation">(</span>b<span class="token operator">+</span>c<span class="token punctuation">)</span>	<span class="token comment">//赋值</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br></div></div><h3 id="例题3"><a href="#例题3" class="header-anchor">#</a> 例题3</h3> <div class="language-cp line-numbers-mode"><pre class="language-text"><code>以下程序的k最终值是：
int i = 10;
int j = 20;
int k = 3;
k *= i + j;
选项：A.90		B.50	C.70	D.30
答案：A
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br></div></div><p>解析：</p> <p>1、贪婪原则，知，经过词法解析后变为了</p> <div class="language-cpp line-numbers-mode"><pre class="language-cpp"><code>k <span class="token operator">*=</span> i <span class="token operator">+</span> j
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>2、优先级和结合性，知，+ up *=</p> <div class="language-cpp line-numbers-mode"><pre class="language-cpp"><code>平行宇宙第<span class="token number">1</span>步：<span class="token punctuation">(</span>i<span class="token operator">+</span>j<span class="token punctuation">)</span>
平行宇宙第<span class="token number">2</span>步：k<span class="token operator">*=</span>第<span class="token number">1</span>步结果
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><h3 id="例题4"><a href="#例题4" class="header-anchor">#</a> 例题4</h3> <div class="language-cpp line-numbers-mode"><pre class="language-cpp"><code>已知<span class="token keyword">int</span> x<span class="token operator">=</span><span class="token number">5</span><span class="token punctuation">;</span>，执行下列语句后，x的值为（  ）。
x<span class="token operator">+=</span>x<span class="token operator">-=</span>x<span class="token operator">*</span>x<span class="token punctuation">;</span>
选项：A<span class="token punctuation">.</span><span class="token number">25</span>	 B<span class="token punctuation">.</span><span class="token number">40</span>	C<span class="token punctuation">.</span>–<span class="token number">40</span>	D<span class="token punctuation">.</span><span class="token number">20</span>
答案：C
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br></div></div><p>解析：</p> <p>1、贪婪原则，知，经过词法解析后变为了</p> <div class="language-cpp line-numbers-mode"><pre class="language-cpp"><code>k <span class="token operator">+=</span> x <span class="token operator">-=</span> x <span class="token operator">*</span> x
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>2、优先级和结合性，知，* up +=和-=，然后结合性，-=和+=是从右到左</p> <div class="language-cpp line-numbers-mode"><pre class="language-cpp"><code>平行宇宙第<span class="token number">1</span>步：<span class="token punctuation">(</span>x<span class="token operator">*</span>x<span class="token punctuation">)</span>
平行宇宙第<span class="token number">2</span>步：x<span class="token operator">-=</span><span class="token punctuation">(</span>第<span class="token number">1</span>步结果<span class="token punctuation">)</span>
平行宇宙第<span class="token number">3</span>步：k<span class="token operator">+=</span>（第<span class="token number">2</span>步结果）
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><h3 id="例题5"><a href="#例题5" class="header-anchor">#</a> 例题5</h3> <div class="language-cpp line-numbers-mode"><pre class="language-cpp"><code>设以下变量均为<span class="token keyword">int</span>类型，表达式的值不为<span class="token number">9</span>的是（）
A<span class="token punctuation">.</span><span class="token punctuation">(</span>x<span class="token operator">=</span>y<span class="token operator">=</span><span class="token number">8</span><span class="token punctuation">,</span>x<span class="token operator">+</span>y<span class="token punctuation">,</span>x<span class="token operator">+</span><span class="token number">1</span><span class="token punctuation">)</span>
B<span class="token punctuation">.</span><span class="token punctuation">(</span>x<span class="token operator">=</span>y<span class="token operator">=</span><span class="token number">8</span><span class="token punctuation">,</span>x<span class="token operator">+</span>y<span class="token punctuation">,</span>y<span class="token operator">+</span><span class="token number">1</span><span class="token punctuation">)</span>
C<span class="token punctuation">.</span><span class="token punctuation">(</span>x<span class="token operator">=</span><span class="token number">8</span><span class="token punctuation">,</span>x<span class="token operator">+</span><span class="token number">1</span><span class="token punctuation">,</span>y<span class="token operator">=</span><span class="token number">8</span><span class="token punctuation">,</span>x<span class="token operator">+</span>y<span class="token punctuation">)</span>
D<span class="token punctuation">.</span><span class="token punctuation">(</span>y<span class="token operator">=</span><span class="token number">8</span><span class="token punctuation">,</span>y<span class="token operator">+</span><span class="token number">1</span><span class="token punctuation">,</span>x<span class="token operator">=</span>y<span class="token punctuation">,</span>x<span class="token operator">+</span><span class="token number">1</span><span class="token punctuation">)</span>
答案：C
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br></div></div><p>解析：</p> <p>核心，优先级</p> <p><code>()</code>是第高</p> <p><code>，</code>是最低</p> <h3 id="例题6"><a href="#例题6" class="header-anchor">#</a> 例题6</h3> <p>宏的复合题型</p> <div class="language-cpp line-numbers-mode"><pre class="language-cpp"><code><span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span><span class="token string">&lt;iostream.h&gt;</span></span>
<span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">define</span> <span class="token macro-name function">SUB</span><span class="token expression"><span class="token punctuation">(</span>X<span class="token punctuation">,</span>Y<span class="token punctuation">)</span> <span class="token punctuation">(</span>X<span class="token punctuation">)</span><span class="token operator">*</span>Y</span></span>
<span class="token keyword">int</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token punctuation">{</span>
    <span class="token keyword">int</span> a<span class="token operator">=</span><span class="token number">3</span><span class="token punctuation">,</span>b<span class="token operator">=</span><span class="token number">4</span><span class="token punctuation">;</span>
    cout<span class="token operator">&lt;&lt;</span>SUB（a<span class="token operator">++</span><span class="token punctuation">,</span><span class="token operator">++</span>b<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token keyword">return</span> <span class="token number">0</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>

答案：输出<span class="token number">15</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br></div></div><p>解析：</p> <p>1、预处理</p> <div class="language-cpp line-numbers-mode"><pre class="language-cpp"><code>cout<span class="token operator">&lt;&lt;</span><span class="token punctuation">(</span>a<span class="token operator">++</span><span class="token punctuation">)</span><span class="token operator">*</span><span class="token operator">++</span>b<span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>2、3步和2注意</p> <div class="language-cpp line-numbers-mode"><pre class="language-cpp"><code>（a<span class="token operator">++</span><span class="token punctuation">)</span> <span class="token operator">*</span> <span class="token operator">++</span>b
平行宇宙第<span class="token number">1</span>步：（a<span class="token operator">++</span><span class="token punctuation">)</span>
平行宇宙第<span class="token number">2</span>步：（<span class="token operator">++</span>b）
平行宇宙第<span class="token number">3</span>步：第<span class="token number">1</span>步结果<span class="token operator">*</span>第<span class="token number">2</span>步结果
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br></div></div><h3 id="例题7"><a href="#例题7" class="header-anchor">#</a> 例题7</h3> <div class="language-cpp line-numbers-mode"><pre class="language-cpp"><code>写出表达式b<span class="token operator">!=</span><span class="token number">3</span><span class="token operator">&amp;&amp;</span><span class="token number">5</span><span class="token operator">/</span>a<span class="token operator">&gt;</span>a<span class="token operator">+</span>b的结果，设a<span class="token operator">=</span><span class="token number">3</span>，b<span class="token operator">=</span><span class="token number">4</span>。
答案是：<span class="token boolean">false</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><p>解析：</p> <p>优先级知道，算术up关系up逻辑up赋值</p> <div class="language-cpp line-numbers-mode"><pre class="language-cpp"><code>b <span class="token operator">!=</span> <span class="token number">3</span> <span class="token operator">&amp;&amp;</span> <span class="token number">5</span> <span class="token operator">/</span> a <span class="token operator">&gt;</span> a <span class="token operator">+</span> b

    b <span class="token operator">!=</span> <span class="token number">3</span> <span class="token operator">&amp;&amp;</span> <span class="token number">5</span> <span class="token operator">/</span> a <span class="token operator">&gt;</span> a <span class="token operator">+</span> b
    （<span class="token number">4</span>）（<span class="token number">5</span>）（<span class="token number">1</span>）（<span class="token number">3</span>） （<span class="token number">2</span>）
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br></div></div><h3 id="补充（博客遗漏之处）："><a href="#补充（博客遗漏之处）：" class="header-anchor">#</a> 补充（博客遗漏之处）：</h3> <p>关系运算符中优先级：&gt;和&lt;和&gt;=和&lt;=比 != 优先级高</p> <h3 id="例题组别（关于逻辑运算返回值）"><a href="#例题组别（关于逻辑运算返回值）" class="header-anchor">#</a> 例题组别（关于逻辑运算返回值）</h3> <div class="language-cpp line-numbers-mode"><pre class="language-cpp"><code>已知a<span class="token operator">=</span><span class="token number">6</span>，b<span class="token operator">=</span><span class="token number">5</span>，c<span class="token operator">=</span><span class="token number">7</span>，d<span class="token operator">=</span><span class="token number">8</span>，则<span class="token punctuation">(</span> <span class="token operator">-</span>a<span class="token punctuation">,</span> b<span class="token operator">&gt;</span>a<span class="token operator">--</span><span class="token operator">&amp;&amp;</span>c<span class="token operator">&gt;</span>d <span class="token punctuation">)</span><span class="token operator">?</span> d<span class="token operator">++</span> <span class="token operator">:</span> a <span class="token operator">&gt;</span> b的值为 。
答案：<span class="token number">0</span>
已有定义： <span class="token keyword">int</span> x<span class="token operator">=</span><span class="token number">3</span><span class="token punctuation">,</span>y<span class="token operator">=</span><span class="token number">4</span><span class="token punctuation">,</span>z<span class="token operator">=</span><span class="token number">5</span> <span class="token punctuation">;</span> ，则表达式 <span class="token operator">!</span><span class="token punctuation">(</span>x<span class="token operator">+</span>y<span class="token punctuation">)</span><span class="token operator">+</span>z<span class="token operator">-</span><span class="token number">1</span><span class="token operator">&amp;&amp;</span>y<span class="token operator">+</span>z<span class="token operator">/</span><span class="token number">2</span> 的值是（ ）
答案：<span class="token number">1</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br></div></div><h2 id="三、题库"><a href="#三、题库" class="header-anchor">#</a> 三、题库</h2> <h3 id="例1"><a href="#例1" class="header-anchor">#</a> 例1</h3> <div class="language-cpp line-numbers-mode"><pre class="language-cpp"><code><span class="token keyword">int</span> a<span class="token operator">=</span><span class="token number">5</span><span class="token punctuation">,</span>b<span class="token operator">=</span><span class="token number">4</span><span class="token punctuation">,</span>c<span class="token operator">=</span><span class="token number">3</span><span class="token punctuation">,</span>d<span class="token punctuation">;</span>
d<span class="token operator">=</span><span class="token punctuation">(</span>a<span class="token operator">&gt;</span>b<span class="token operator">&gt;</span>c<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;%d\n&quot;</span><span class="token punctuation">,</span>d<span class="token punctuation">)</span><span class="token punctuation">;</span>
答案：<span class="token number">0</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br></div></div><p>解析：</p> <p>d = ( a &gt; b &gt; c )</p> <p><code>&gt;</code>的结合性是从左边到右边</p> <h3 id="例2"><a href="#例2" class="header-anchor">#</a> 例2</h3> <div class="language-cpp line-numbers-mode"><pre class="language-cpp"><code>若整型变量a、b、c、d中的值依次为：<span class="token number">1</span>、<span class="token number">4</span>、<span class="token number">3</span>、<span class="token number">2</span>。则条件表达式a<span class="token operator">&lt;</span>b<span class="token operator">?</span>a<span class="token operator">:</span>c<span class="token operator">&lt;</span>d<span class="token operator">?</span>c<span class="token operator">:</span>d的值 <span class="token punctuation">(</span>   <span class="token punctuation">)</span>  。
答案：<span class="token number">1</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><p>解析：</p> <p>等价于</p> <div class="language-cpp line-numbers-mode"><pre class="language-cpp"><code><span class="token keyword">if</span><span class="token punctuation">(</span> a<span class="token operator">&lt;</span>b <span class="token punctuation">)</span>
<span class="token punctuation">{</span>
    <span class="token keyword">return</span> a<span class="token punctuation">;</span>
<span class="token punctuation">}</span>
<span class="token keyword">else</span>
<span class="token punctuation">{</span>
    <span class="token keyword">if</span><span class="token punctuation">(</span> c<span class="token operator">&lt;</span>d <span class="token punctuation">)</span>
    <span class="token punctuation">{</span>
        <span class="token keyword">return</span> c<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
    <span class="token keyword">else</span>
    <span class="token punctuation">{</span>
        <span class="token keyword">return</span> d<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br></div></div><h3 id="例3"><a href="#例3" class="header-anchor">#</a> 例3</h3> <h2 id="四、似乎是方法之外的题目"><a href="#四、似乎是方法之外的题目" class="header-anchor">#</a> 四、似乎是方法之外的题目</h2> <h3 id="（1），逗号分隔非平行宇宙——一般情况"><a href="#（1），逗号分隔非平行宇宙——一般情况" class="header-anchor">#</a> （1），逗号分隔非平行宇宙——一般情况</h3> <div class="language-cpp line-numbers-mode"><pre class="language-cpp"><code>设 <span class="token keyword">int</span> a<span class="token punctuation">,</span>b<span class="token punctuation">,</span>c<span class="token punctuation">;</span> 执行表达式 a<span class="token operator">=</span>b<span class="token operator">=</span><span class="token number">1</span> ， a<span class="token operator">++</span> ， b<span class="token operator">+</span><span class="token number">1</span> ， c<span class="token operator">=</span>a<span class="token operator">+</span>b<span class="token operator">--</span> 后， a<span class="token punctuation">,</span>b 和 c 的值分别是
答案<span class="token operator">:</span> B 
A <span class="token number">2</span><span class="token punctuation">,</span><span class="token number">1</span><span class="token punctuation">,</span><span class="token number">2</span>
B <span class="token number">2</span><span class="token punctuation">,</span><span class="token number">0</span><span class="token punctuation">,</span><span class="token number">3</span>
C <span class="token number">2</span><span class="token punctuation">,</span><span class="token number">2</span><span class="token punctuation">,</span><span class="token number">3</span>
D <span class="token number">2</span><span class="token punctuation">,</span><span class="token number">1</span><span class="token punctuation">,</span><span class="token number">3</span>

</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br></div></div><p>如果用，优先级，似乎a++和b--最先开始，那么b就不确定。</p> <p>纠错：</p> <p>1、有逗号表达式的，将所有句子按照,号分隔。然后从左边往右进行局部的句子整体</p> <p>2、有逗号表达式的题目，要先化为等价的句子</p> <p>解析：</p> <div class="language-cpp line-numbers-mode"><pre class="language-cpp"><code><span class="token keyword">int</span> a<span class="token punctuation">,</span>b<span class="token punctuation">,</span>c<span class="token punctuation">;</span> 
a<span class="token operator">=</span>b<span class="token operator">=</span><span class="token number">1</span> <span class="token punctuation">,</span> a<span class="token operator">++</span><span class="token punctuation">,</span> b<span class="token operator">+</span><span class="token number">1</span> <span class="token punctuation">,</span> c<span class="token operator">=</span>a<span class="token operator">+</span>b<span class="token operator">--</span> <span class="token punctuation">;</span>
<span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;%d %d %d\n&quot;</span><span class="token punctuation">,</span>a<span class="token punctuation">,</span>b<span class="token punctuation">,</span>c<span class="token punctuation">)</span><span class="token punctuation">;</span>
由于末尾没有特殊情况（特殊情况见下面），所以可以等价于
a<span class="token operator">=</span>b<span class="token operator">=</span><span class="token number">1</span><span class="token punctuation">;</span>
a<span class="token operator">++</span><span class="token punctuation">;</span><span class="token comment">//这个地方a=1</span>
b<span class="token operator">+</span><span class="token number">1</span><span class="token punctuation">;</span><span class="token comment">//注意，这里a=2了（副作用显现）</span>
c<span class="token operator">=</span>a<span class="token operator">+</span>b<span class="token operator">--</span><span class="token punctuation">;</span>

</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br></div></div><h3 id="（2），逗号分隔非平行宇宙——特殊情况"><a href="#（2），逗号分隔非平行宇宙——特殊情况" class="header-anchor">#</a> （2），逗号分隔非平行宇宙——特殊情况</h3> <div class="language-cpp line-numbers-mode"><pre class="language-cpp"><code><span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span><span class="token string">&lt;bits/stdc++.h&gt;</span></span>
<span class="token keyword">using</span> <span class="token keyword">namespace</span> std<span class="token punctuation">;</span> 

<span class="token keyword">int</span>  <span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token punctuation">{</span>
	 <span class="token keyword">int</span> a<span class="token punctuation">,</span>temp<span class="token punctuation">;</span> 
	 a<span class="token operator">=</span><span class="token number">1</span><span class="token punctuation">;</span>
	 a<span class="token operator">+</span><span class="token number">5</span><span class="token punctuation">;</span>
	 a<span class="token operator">++</span><span class="token punctuation">;</span> 
	 <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;%d \n&quot;</span><span class="token punctuation">,</span>a<span class="token punctuation">)</span><span class="token punctuation">;</span>	<span class="token comment">//（1）输出2</span>
	 
	 <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;%d \n&quot;</span><span class="token punctuation">,</span>a<span class="token operator">=</span><span class="token number">1</span><span class="token punctuation">,</span>a<span class="token operator">+</span><span class="token number">5</span><span class="token punctuation">,</span>a<span class="token operator">++</span><span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token comment">//（2）输出1	（HuNan University考研真题）</span>
	 
	 temp<span class="token operator">=</span><span class="token punctuation">(</span>a<span class="token operator">=</span><span class="token number">1</span><span class="token punctuation">,</span>a<span class="token operator">+</span><span class="token number">5</span><span class="token punctuation">,</span>a<span class="token operator">++</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
	 <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;%d \n&quot;</span><span class="token punctuation">,</span>temp<span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token comment">//（3）输出1</span>
	 
	 <span class="token keyword">return</span> <span class="token number">0</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>

</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br></div></div><p>如上，如果逗号表达式的最终有一步a++</p> <p>如何马上进行返回，那么副作用无法马上进行，所以，（2）和（3）输出是1</p> <p>但是如果将这种特殊情况进行等价为（1）上面的，就会给副作用的产生提供机遇。</p> <h2 id="五、相似却不是这个考点的题目"><a href="#五、相似却不是这个考点的题目" class="header-anchor">#</a> 五、相似却不是这个考点的题目</h2> <h3 id="（1）例1"><a href="#（1）例1" class="header-anchor">#</a> （1）例1</h3> <div class="language-cpp line-numbers-mode"><pre class="language-cpp"><code><span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span><span class="token string">&lt;bits/stdc++.h&gt;</span></span>
<span class="token keyword">using</span> <span class="token keyword">namespace</span> std<span class="token punctuation">;</span> 

<span class="token keyword">int</span>  <span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token punctuation">{</span>
	<span class="token keyword">int</span> i<span class="token operator">=</span><span class="token number">3</span><span class="token punctuation">;</span>
	cout<span class="token operator">&lt;&lt;</span><span class="token operator">-</span>i<span class="token operator">++</span><span class="token operator">&lt;&lt;</span>endl<span class="token punctuation">;</span><span class="token comment">//输出竟然是-3</span>
	<span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;%d\n&quot;</span><span class="token punctuation">,</span>i<span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token comment">//输出4</span>
	cout<span class="token operator">&lt;&lt;</span>i<span class="token operator">&lt;&lt;</span>endl<span class="token punctuation">;</span><span class="token comment">//输出4</span>
	<span class="token keyword">return</span> <span class="token number">0</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br></div></div><p>解析：</p> <p>首先i++，表达式完成前，4的值是一个临时变量，i本身还是3，再执行取负运算。</p> <h3 id="（2）例2（你真的搞懂了我编的口诀？）"><a href="#（2）例2（你真的搞懂了我编的口诀？）" class="header-anchor">#</a> （2）例2（你真的搞懂了我编的口诀？）</h3> <div class="language-cpp line-numbers-mode"><pre class="language-cpp"><code>运算符的优先级正确排序是：
赋值运算符＜逻辑运算符＜关系运算符＜算术运算符。
答案：错误
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><p>解析：可能有人记忆我的口诀会误以为，逻辑运算符全在算术运算符后面。</p> <p>但是，请深刻理解口诀，单目运算符在算法运算符前面，比如我们的既是单目运算符又是逻辑运算符的！就在前面</p> <h3 id="（3）你以为我是在考优先级"><a href="#（3）你以为我是在考优先级" class="header-anchor">#</a> （3）你以为我是在考优先级?</h3> <ul><li>其实是在考“短路原则”</li></ul> <div class="language-cpp line-numbers-mode"><pre class="language-cpp"><code>若定义了<span class="token keyword">int</span> m<span class="token operator">=</span><span class="token number">1</span><span class="token punctuation">,</span>n<span class="token operator">=</span><span class="token number">2</span><span class="token punctuation">;</span>在执行了<span class="token operator">--</span>m<span class="token operator">&amp;&amp;</span>n<span class="token operator">++</span><span class="token punctuation">;</span><span class="token operator">++</span>m<span class="token operator">||</span>n<span class="token operator">++</span><span class="token punctuation">;</span>这<span class="token number">2</span>条语句后，n的值为？
答案<span class="token operator">:</span> A
A <span class="token number">2</span>
B <span class="token number">3</span>
C <span class="token number">4</span>
D <span class="token number">1</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br></div></div><h3 id="（4）（易错！！）这次我真的在考“优先级”，顺路考“短路原则”（短路优先原则的逆袭）"><a href="#（4）（易错！！）这次我真的在考“优先级”，顺路考“短路原则”（短路优先原则的逆袭）" class="header-anchor">#</a> （4）（易错！！）这次我真的在考“优先级”，顺路考“短路原则”（短路优先原则的逆袭）</h3> <div class="language-cpp line-numbers-mode"><pre class="language-cpp"><code><span class="token keyword">int</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span>	<span class="token comment">//360公司 招聘真题</span>
<span class="token punctuation">{</span>
    <span class="token keyword">int</span> a<span class="token operator">=</span><span class="token number">1</span><span class="token punctuation">,</span>b<span class="token operator">=</span><span class="token number">2</span><span class="token punctuation">,</span>m<span class="token operator">=</span><span class="token number">0</span><span class="token punctuation">,</span>n<span class="token operator">=</span><span class="token number">0</span><span class="token punctuation">,</span>k<span class="token punctuation">;</span>
    
    k<span class="token operator">=</span><span class="token punctuation">(</span>n<span class="token operator">=</span>b<span class="token operator">&lt;</span>a<span class="token punctuation">)</span><span class="token operator">&amp;&amp;</span><span class="token punctuation">(</span>m<span class="token operator">=</span>a<span class="token punctuation">)</span> <span class="token punctuation">;</span>
    <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;%d,%d\n&quot;</span><span class="token punctuation">,</span>k<span class="token punctuation">,</span>m<span class="token punctuation">)</span><span class="token punctuation">;</span>
    
    <span class="token keyword">return</span> <span class="token number">0</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
答案：A	易错选：B（结合性的理解出错？）
A <span class="token number">0</span><span class="token punctuation">,</span><span class="token number">0</span>
B <span class="token number">0</span><span class="token punctuation">,</span><span class="token number">1</span>
C <span class="token number">1</span><span class="token punctuation">,</span><span class="token number">0</span>
D <span class="token number">1</span><span class="token punctuation">,</span><span class="token number">1</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br></div></div><p>解释：</p> <ul><li>错误分析方式：</li></ul> <p>1、优先级，初级运算符先开始，从左边到右边</p> <div class="language-cpp line-numbers-mode"><pre class="language-cpp"><code>平行宇宙第<span class="token number">1</span>步<span class="token punctuation">(</span> n<span class="token operator">=</span> <span class="token punctuation">(</span>b<span class="token operator">&lt;</span>a<span class="token punctuation">)</span> <span class="token punctuation">)</span>这个之后，n<span class="token operator">=</span><span class="token number">0</span>， m<span class="token operator">=</span><span class="token number">0</span>
平行宇宙第<span class="token number">2</span>步<span class="token punctuation">(</span> m<span class="token operator">=</span>a <span class="token punctuation">)</span>这个m<span class="token operator">=</span><span class="token number">1</span> （错误的地方在这）
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><ul><li>正确分析方式：</li></ul> <p>错误的地方，我们需要理解结合性，到这个地方，我们？？？<font>（这个，我也不会解释。。。）</font></p> <ul><li>思考了一阵子之后，还是想，前面的方法，都是我的猜测，有点忽略了“编译器”是用“DFA”自动机，进行识别的。</li> <li>所以，修正前面的方法，我们在进行词法分析之后，优先级啥的分析之前，我们需要将“&amp;&amp;和||”这样的具有“短路原则”的情况，额外拿出。</li></ul> <div class="language-cpp line-numbers-mode"><pre class="language-cpp"><code><span class="token keyword">int</span> a<span class="token operator">=</span><span class="token number">5</span><span class="token punctuation">,</span>b<span class="token operator">=</span><span class="token number">3</span><span class="token punctuation">;</span>	<span class="token comment">//招商银行信用卡中心 招聘真题</span>
<span class="token operator">!</span>a<span class="token operator">&amp;&amp;</span>b<span class="token operator">++</span><span class="token punctuation">;</span> 
	
<span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;%d %d&quot;</span><span class="token punctuation">,</span>a<span class="token punctuation">,</span>b<span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token comment">//输出是5 3</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br></div></div><p>解析：</p> <p>正确分析</p> <div class="language-cpp line-numbers-mode"><pre class="language-cpp"><code><span class="token operator">!</span> a <span class="token operator">&amp;&amp;</span> b <span class="token operator">++</span>
然后<span class="token number">0</span> <span class="token operator">&amp;&amp;</span> b <span class="token operator">++</span>
短路原则得到<span class="token number">0</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><p>错误分析</p> <div class="language-cpp line-numbers-mode"><pre class="language-cpp"><code><span class="token operator">!</span> a <span class="token operator">&amp;&amp;</span> b <span class="token operator">++</span>
然后<span class="token number">0</span> <span class="token operator">&amp;&amp;</span> b <span class="token operator">++</span>
优先级，然后<span class="token number">0</span> <span class="token operator">&amp;&amp;</span> <span class="token number">4</span> <span class="token comment">//b=4</span>
短路原则得到<span class="token number">0</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br></div></div><h3 id="（5）结合性和指针结合"><a href="#（5）结合性和指针结合" class="header-anchor">#</a> （5）结合性和指针结合</h3> <div class="language-cpp line-numbers-mode"><pre class="language-cpp"><code><span class="token operator">*</span>p<span class="token operator">++</span> 自增p 还是 p 所指向的变量<span class="token operator">?</span>
答案：A
A 先自增p
B 先自增p所指向的变量
C 和机器相关

</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br></div></div><p>解析：优先级，*和++同级，但是结合性是从右边到左边，等价于</p> <div class="language-cpp line-numbers-mode"><pre class="language-cpp"><code><span class="token operator">*</span><span class="token punctuation">(</span> p<span class="token operator">++</span> <span class="token punctuation">)</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h3 id="（6）优先级和类型升级结合"><a href="#（6）优先级和类型升级结合" class="header-anchor">#</a> （6）优先级和类型升级结合</h3> <div class="language-cpp line-numbers-mode"><pre class="language-cpp"><code>假定x和y为<span class="token keyword">double</span>型，则表达式x<span class="token operator">=</span><span class="token number">2</span>，y<span class="token operator">=</span>x<span class="token operator">+</span><span class="token number">3</span><span class="token operator">/</span><span class="token number">2</span>的值是
答案<span class="token operator">:</span> D 
A <span class="token number">3.500000</span>
B <span class="token number">3</span>
C <span class="token number">2.000000</span>
D <span class="token number">3.000000</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br></div></div><h3 id="（7）易错"><a href="#（7）易错" class="header-anchor">#</a> （7）易错</h3> <div class="language-cpp line-numbers-mode"><pre class="language-cpp"><code><span class="token keyword">int</span> a<span class="token operator">=</span><span class="token number">4</span><span class="token punctuation">,</span>则对于表达式<span class="token operator">++</span><span class="token punctuation">(</span>a<span class="token operator">++</span><span class="token punctuation">)</span>的结果说法正确的是（）
答案<span class="token operator">:</span> D 
A 结果为<span class="token number">5</span>
B 结果为<span class="token number">6</span>
C 结果为<span class="token number">7</span>
D 以上不都是
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br></div></div><p>解析</p> <p>a++的结果是4，然后进行++4是不对的，++运算只是针对于变量的，<strong>不能对常量</strong>来进行++运算。</p> <h2 id="六、c-中运算符"><a href="#六、c-中运算符" class="header-anchor">#</a> 六、C++中运算符</h2> <div class="language-cpp line-numbers-mode"><pre class="language-cpp"><code>若有<span class="token keyword">int</span> i<span class="token operator">=</span><span class="token number">3</span><span class="token punctuation">,</span><span class="token operator">*</span>p<span class="token punctuation">;</span>p<span class="token operator">=</span><span class="token operator">&amp;</span>i<span class="token punctuation">;</span>输出结果为<span class="token number">3</span>的是 cout<span class="token operator">&lt;&lt;</span><span class="token operator">*</span>p？
答案：正确
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><h2 id="七、true和false你真的了解吗？"><a href="#七、true和false你真的了解吗？" class="header-anchor">#</a> 七、true和false你真的了解吗？</h2> <div class="language-cpp line-numbers-mode"><pre class="language-cpp"><code>已知有如下的变量定义，那么第二行的表达式的值是多少（）
<span class="token keyword">int</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token keyword">void</span><span class="token punctuation">)</span>
<span class="token punctuation">{</span>
    <span class="token keyword">int</span> x <span class="token operator">=</span> <span class="token number">3</span> <span class="token punctuation">,</span> y <span class="token operator">=</span> <span class="token number">4</span> <span class="token punctuation">,</span> z <span class="token operator">=</span> <span class="token number">5</span><span class="token punctuation">;</span>
    <span class="token operator">!</span><span class="token punctuation">(</span>x <span class="token operator">+</span> y<span class="token punctuation">)</span> <span class="token operator">+</span> z<span class="token operator">-</span><span class="token number">1</span> <span class="token operator">&amp;&amp;</span> y <span class="token operator">+</span> z<span class="token operator">/</span><span class="token number">2</span><span class="token punctuation">;</span>
    <span class="token keyword">return</span> <span class="token number">0</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
正确答案<span class="token operator">:</span> D  
A <span class="token number">6</span>
B <span class="token number">2</span>
C <span class="token number">0</span>
D <span class="token number">1</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br></div></div><ul><li>1、if和while啥的判断一个int，只要不是0，就认为是true，if( -1 )效果和if(true)一样</li> <li>2、我们用判断a &amp;&amp; b啥得到的true和false如果用int承载却直接对应的是1和0！！！</li> <li>3、（注意记住上面2点）</li></ul> <h2 id="八、sizeof真的是运算符"><a href="#八、sizeof真的是运算符" class="header-anchor">#</a> 八、sizeof真的是运算符</h2> <div class="language-cpp line-numbers-mode"><pre class="language-cpp"><code>下面程序的输出是<span class="token operator">:</span>
<span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span> <span class="token string">&lt;stdio.h&gt;</span></span>
<span class="token keyword">int</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token punctuation">{</span>
    <span class="token keyword">int</span> i <span class="token operator">=</span> <span class="token number">1</span><span class="token punctuation">;</span>
    <span class="token keyword">sizeof</span><span class="token punctuation">(</span>i<span class="token operator">++</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">&quot;%d\n&quot;</span><span class="token punctuation">,</span> i<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token keyword">return</span> <span class="token number">0</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
答案：A
A <span class="token number">1</span>
B <span class="token number">4</span>
C <span class="token number">2</span>
D <span class="token number">8</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br></div></div><p>解析（复制别人的解释）：</p> <ul><li>根据C99规范， <code>sizeof</code>是一个编译时刻就起效果的运算符，在其内的任何运算都没有意义，</li> <li>sizeof(i++); 在编译的时候被翻译成</li> <li>sizeof((i++的数据类型)) 也就是 sizeof(int); 不会执行i++了。</li> <li>sizeof是运算符,它在<strong>编译</strong>时起作用，而不是运行时。</li> <li>也就是说，在编译时，就得到了sizeof(int)，运行时，i++根本没有执行过。</li></ul></div> <div class="page-edit"><!----> <!----></div> <!----> </div> <!----></div></div>
    <script src="/assets/js/app.c70e21ad.js" defer></script><script src="/assets/js/22.f78666de.js" defer></script>
  </body>
</html>
